from pythonds.basic.stack import Stack


def parChecker(symbolString):
    stack = Stack()
    balanced = True
    index = 0
    while index < len(symbolString) and balanced:
        symbol = symbolString[index]
        if symbol in '({[':
            stack.push(symbol)
        else:
            if stack.isEmpty():
                balanced = False  # 只有一个右括号但是没有入栈
            else:
                top = stack.pop()
                if not matches(top, symbol): # 判断弹出来的是否一直
                    balanced = False
        index += 1
    if balanced and stack.isEmpty():
        return True
    else:
        return False


def matches(open, closer):
    opens = '{(['
    closers = '})]'
    return opens.index(open) == closers.index(closer)


print(parChecker('{{{]])}}}'))  # False

